import Ability from '@ohos.application.Ability'
import  SysPermissionUtils from '../util/SysPermissionUtils';

export default class PlayerAbility extends Ability {
    onCreate(want, launchParam) {
        console.log("[Demo] MainAbility onCreate")
        globalThis.abilityWant = want;

        let abilityInfo = this.context.abilityInfo;
        globalThis.bundleName = abilityInfo.bundleName
        globalThis.context = this.context
        globalThis.LogTag = 'cwq'
        globalThis.isShowLog = true
        globalThis.display
        globalThis.abilityContext= this.context
    }

    onDestroy() {
        console.log("[Demo] MainAbility onDestroy")
    }

    onWindowStageCreate(windowStage) {
        // Main window is created, set main page for this ability
        console.log("[Demo] MainAbility onWindowStageCreate")

        globalThis.requestPermissions = (() => {
            return SysPermissionUtils.requestWithinNecessary(null,
                ["ohos.permission.READ_MEDIA",
                "ohos.permission.WRITE_MEDIA",
                "ohos.permission.MEDIA_LOCATION"
                ]
            )
        })


        windowStage.setUIContent(this.context, "pages/video_player", null)
    }

    onWindowStageDestroy() {
        // Main window is destroyed, release UI related resources
        console.log("[Demo] MainAbility onWindowStageDestroy")
    }

    onForeground() {
        // Ability has brought to foreground
        console.log("[Demo] MainAbility onForeground")
    }

    onBackground() {
        // Ability has back to background
        console.log("[Demo] MainAbility onBackground")
    }
};
